var app = getApp()
const generatetestusersig = require("../../../webrtc-room/debug/generatetestusersig.js");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    argeen: false,
    inquiry: "1", // "" 家庭医生支付  ！"" 问诊
    switchChecked: false,
    radio: false,
    coupon: '',
    coupon_id: '',
    coupon_dk: '',
    money: "",
    old_money: "",
    xiangqing: [],
    coupon_title: "暂无优惠券可用",
    is_yearcard: false,
    checked: false,
    yearcard: "",
    useryear: false,
    zhuanjia_year: false,
    is_year: false,
    zid: "",
    fuwus: "",
    lvtong: "",
    time: "",
    timeText_start: "",
    timeText_end: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var money = options.money
    var zid = options.zid
    var conets = JSON.parse(options.conets)
    var key_words = options.key_words
    var cfstate = options.cfstate
    var j_id = options.j_id
    var time_leng = 1 //时长
    var phone = options.phone
    var data_time = options.data_time
    var week = options.week
    var month_time = options.month_time
    var addnum = options.addnum
    var privateNum = options.privateNum
    //标签
    if (options.tjorder) {
      var tjorder = options.tjorder
      that.setData({
        tjorder: tjorder
      })
    }
    if (options.arr !== 'undefined') {
      var arr = JSON.parse(options.arr)
      that.setData({
        arr: arr
      })
    }


    if (options.inquiry) {
      var inquiry = options.inquiry
      that.setData({
        inquiry: inquiry
      })
    }
    // 优惠券
    // 优惠券
    console.log(options)
    var leixing = options.leixing;
    if (leixing == 'lvtong') {
      that.setData({
        did: options.did,
        server: options.server,
        money: options.money,
        hid: options.hid,
        keshi_two: options.keshi_two,
        tid: options.tid,
        conets: options.conets,
        leixing: options.leixing,
        cfstate: options.cfstate,
        week: options.week,
        arr: options.arr,
        time: options.time,
        fuwus: options.fuwus,
        time: options.time,
        timeText_start: options.timeText_start,
        timeText_end: options.timeText_end,
      })
    }
    app.util.request({
      'url': 'entry/wxapp/hzbingli.url',
      success: function (res) {
        console.log(res)
        that.setData({
          url: res.data,
        })
      }
    })
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.getserverinfo',
      data: {
        key_words: key_words,

      },
      success: function (res) {
        console.log(res)
        that.setData({
          html: res.data.buyreading
        })
      }
    })
    that.setData({
      zid: zid,
      key_words: key_words,
      cfstate: cfstate,
      conets: conets,
      old_money: money,
      j_id: j_id,
      time_leng: time_leng,
      phone: phone,
      data_time: data_time,
      week: week,
      month_time: month_time,
      roomID: 123456,
      text: conets.text,
      addnum: addnum,
      privateNum: privateNum,
      zmoney: money
    })

    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    this.setData({
      bgc: bgc
    })
    if (options.leixing != 'lvtong') {
      that.getYearcard();
      app.util.request({
        'url': 'entry/wxapp/zhuanjia.docinfo',
        data: {
          zid: zid,
          key: key_words
        },
        success: function (res) {
          console.log(res)
          that.setData({
            xiangqing: res.data,
            z_telephone: res.data.z_telephone,
            money: res.data.money,
            old_money: res.data.money,
            privateNum: res.data.privateNum,
            addnum: parseInt(res.data.ptzhuiw),
            advertisement: res.data.advertisement,
            z_name: res.data.z_name
          })
          that.getCoupon();
        }
      })
      app.util.request({
        'url':"entry/wxapp/zhuanjia.get_money",
        data:{
          openid:wx.getStorageSync('openid'),
          zid:that.data.zid,
          money:that.data.zmoney,
          key_words:that.data.key_words
        },
        success:function(res)
        {
          console.log(res);
          that.setData({
            zmoney:res.data.money
          })
          console.log(that.data.zmoney)
        }
      })
      // 获取专家年卡
      that.getzhuanjia_year();
      // 获取用户年卡
      that.getuser_year();
    } else if (options.did != '' && options.did != 'undefined' && options.did != undefined) {
      that.getDocinfo();
    } else if (options.zid != '') {
      that.setData({
        zid: options.zid
      })
      that.getzhuanjiainfo();
    }

  },
  // 获取专家信息
  getzhuanjiainfo: function () {
    var that = this;
    app.util.request({
      'url': "entry/wxapp/zhuanjia.docinfo",
      data: {
        zid: that.data.zid,
        openid: wx.getStorageSync('openid'),
      },
      success: function (res) {
        that.setData({
          xiangqing: res.data
        })
      }
    })
  },
  // 获取导诊信息
  getDocinfo: function () {
    var that = this;
    app.util.request({
      'url': "entry/wxapp/green.dz_info",
      data: {
        id: that.data.did,
      },
      success: function (res) {

        that.setData({
          xiangqing: res.data,

        })
      }
    })
  },
  // 获取专家年卡
  getzhuanjia_year: function (e) {
    var that = this;
    app.util.request({
      'url': "entry/wxapp/zhuanjia.zhuanjia_year",
      data: {
        openid: wx.getStorageSync('openid'),
        zid: that.data.zid
      },
      success: function (res) {

        if (res.data != '' && res.data != false) {
          that.setData({
            zhuanjia_year: true,
            zj_year: res.data
          })
        } else {
          that.setData({
            zhuanjia_year: false,
          })
        }
      }
    })
  },
  // 获取用户年卡
  getuser_year: function () {
    var that = this;
    app.util.request({
      'url': "entry/wxapp/team.user_year",
      data: {
        openid: wx.getStorageSync('openid'),
        zid: that.data.zid
      },
      success: function (res) {
        if (res.data != '' && res.data != false) {
          that.setData({
            useryear: true
          })
        } else {
          that.setData({
            useryear: false
          })
        }

      }
    })
  },
  // 获取用户优惠券
  getCoupon: function (e) {
    var that = this;
    app.util.request({
      'url': "entry/entry/zhuanjia.user_coupons",
      data: {
        openid: wx.getStorageSync('openid'),
        key_words: that.data.key_words,
        zid: that.data.zid,
        money: that.data.old_money
      },
      success: function (res) {
        // if(res.data != '' && res.data != false)
        // {
        //   that.setData({
        //     coupon:res.data,
        //     coupon_id:res.data.id,
        //     coupon_dk:res.data.deductible_amount,
        //     coupon_title:res.data.coupon_name
        //   })
        // }
      }
    })
  },
  // 年卡选择
  yearcard: function (e) {
    var that = this;
    var radio = that.data.radio;
    var that = this
    var zid = that.data.zid
    var key_words = that.data.key_words
    console.log(radio)
    if (radio) {
      that.setData({
        is_year: false
      })
    } else {
      that.setData({
        is_year: true
      })
    }
    app.util.request({
      'url': "entry/wxapp/zhuanjia.pay_money",
      data: {
        zid: zid,
        openid: wx.getStorageSync('openid'),
        key_words: key_words,
        money: that.data.zmoney,
        is_year: that.data.is_year
      },
      success: function (res) {
        that.setData({
          zmoney: res.data.money
        })
      }
    })

    // if(radio)
    // {
    //   if(money == '0.00')
    //   {
    //     wx.showModal({
    //       title: '提示',
    //       content:"此次问诊需要0元，是否确认开启年卡",
    //       success:function(con)
    //       {
    //         var 
    //       }
    //     })
    //   }
    //   var yearcard = that.data.yearcard;
    //   var key_words = that.data.key_words;
    //   if(key_words == 'tuwenwenzhen' && yearcard.wz_num > 0)
    //   {
    //     that.setData({
    //       money:'0.00'
    //     })
    //   }else if(key_words == 'tuwenwenzhen' && yearcard.wx_num == 0)
    //   {
    //     var money = that.data.money;

    //   }
    //   // if(yearcard.)
    // }
  },
  // 获取用户年卡
  getYearcard: function () {
    var that = this;
    app.util.request({
      'url': "entry/wxapp/zhuanjia.user_year",
      data: {
        openid: wx.getStorageSync('openid'),
        zid: that.data.zid,
      },
      success: function (res) {
        console.log(res);
        if (res.data != '' && res.data != false) {
          that.setData({
            yearcard: res.data,
            is_yearcard: true
          })
        } else {
          that.setData({
            is_yearcard: false
          })

        }

      }
    })
  },
  // 是否同意协议
  radioChange(e) {
    e.currentTarget.dataset.argeen = !e.currentTarget.dataset.argeen
    this.setData({
      argeen: e.currentTarget.dataset.argeen,
      agreement_state: true
    })
  },
  // 查看签约协议
  bindiqanyue() {

  },
  // 查看问诊协议详情
  bindwenzhen() {
    console.log("查看问诊协议详情")
    this.setData({
      agreement_state: true
    })
  },
  closezhe: function () {
    this.setData({
      agreement_state: false
    })
  },
  //公开 开关
  switchChange() {
    this.setData({
      switchChecked: !this.data.switchChecked
    })
  },
  // 修改服务包次数开关
  getUpdate:function(){
    var that = this;
    var openid = wx.getStorageSync('openid')
    var zid = that.data.zid
    var key_words = that.data.key_words
    var j_id = that.data.j_id
    app.util.request({
      'url':"entry/wxapp/follow.edit_num",
      data:{
        openid:openid,
        zid:zid,
        key_words:key_words,
        j_id:j_id
      },
      success:function(res)
      {
        
      }
    })
  },
  //支付按钮
  paybtn(e) {
    var that = this
    var openid = wx.getStorageSync('openid')
    var old_money = that.data.old_money;
    var money = that.data.money
    var zid = that.data.zid
    var key_words = that.data.key_words
    var cfstate = that.data.cfstate
    var conets = that.data.conets
    var j_id = that.data.j_id
    var argeen = that.data.argeen
    var switchChecked = that.data.switchChecked
    var uniacid = app.siteInfo.uniacid
    var roomID = that.data.roomID
    e.currentTarget.dataset.imgArr = that.data.imgArr
    console.log(generatetestusersig)
    that.data.userID = new Date().getTime().toString(16);
    var userSig = generatetestusersig.gentestusersig(that.data.userID);
    var addnum = that.data.addnum
    var yid = that.data.yid;
    var privateNum = that.data.privateNum
    var biaoqian = that.data.arr;
    var leixing = that.data.leixing
    var tkid = app.globalData.tkid //一级
    var mytkid = app.globalData.mytkid //二级
    var ziji = app.globalData.ziji //查询当前是不是自己是一级分销商
    console.log(tkid, mytkid, ziji)
    if (!switchChecked) {
      var ifgk = 0
    } else {
      var ifgk = 1
    }

    if (!argeen) {
      wx.showToast({
        title: '请勾选问诊协议',
        icon: 'none'
      })
      return false;
    }
    wx.showModal({
      title: '提示',
      content: "是否确认支付",
      success: function (con) {
        if (con.confirm) {
          if (leixing != 'lvtong') {

            app.util.request({
              'url': "entry/wxapp/zhuanjia.pay_money",
              data: {
                zid: zid,
                openid: wx.getStorageSync('openid'),
                key_words: key_words,
                money: that.data.zmoney,
                is_year: that.data.is_year
              },
              success: function (res) {
                console.log(res)
                if (that.data.is_year) {
                  //提醒
                  app.util.request({
                    'url': 'entry/wxapp/user.memberopentx',
                    data: {
                      near: '年开开通提醒',
                      openid: wx.getStorageSync('openid'),
                    },
                    success: function (res) {
                      console.log(res)
                    }
                  })
                }
                var pay_info = res.data;
                if (pay_info.money !== 'undefined') {
                  var paymoney = pay_info.money
                } else {
                  var paymoney = that.data.money
                }

                if (paymoney == '0.00') {
                  var title = '是否问诊';
                } else {
                  var title = '是否支付';
                }
                if (that.data.inquiry == '-1') {
                  console.log("-------------------------------------处方")
                  wx.showModal({
                    title: title,
                    success: function (res) {
                      if (res.confirm) {
                        app.util.request({
                          'url': 'entry/wxapp/user.addcforder',
                          data: {
                            openid: wx.getStorageSync('openid'),
                            zid: zid,
                            key_words: key_words,
                            cfstate: cfstate,
                            conets: conets,
                            money: pay_info.money,
                            j_id: j_id,
                            ifgk: ifgk,
                            addnum: addnum,
                            coupon_dk: pay_info.coupon_dk,
                            old_money: old_money,
                            coupon_id: pay_info.coupon_id,
                            yid: pay_info.yid,
                            year_dk: pay_info.year_dk
                          },
                          success: function (res) {
                            var orders = res.data.orders
                            var back_orser = res.data.back_orser
                            var id = res.data.id
                            var overtime = res.data.overtime
                            var ifgb = res.data.ifgb
                            var ifpay = res.data.ispay
                            var c_id = res.data.c_id
                            if (ifgk == 1) {
                              app.util.request({
                                'url': 'entry/wxapp/user.openquestion',
                                data: {
                                  id: id,
                                  key_words: key_words,
                                  back_orser: back_orser
                                },
                                success: function (res) {
                                  console.log(res)
                                }
                              })
                            }
                            if (paymoney == '0.00') {
                              that.getUpdate();
                              app.util.request({
                                'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
                                data: {
                                  id: id,
                                  val: conets.text,
                                  near: '开处方',
                                  zid: zid,
                                  type: "user"
                                },
                                success: function (res) {
                                  console.log(res)
                                }
                              })
                              app.util.request({
                                'url': 'entry/wxapp/yuyue.kfangmsgdh',
                                data: {
                                  orders: orders,
                                  text: '用户申请开方'
                                },
                                success: function (res) {
                                  console.log(res)
                                }
                              })
                              wx.navigateTo({
                                url: '../zhifuend/zhifuend?txt=yes&zid=' + that.data.zid + '&back_orser=' + back_orser + '&key_words=' + key_words + '&j_id=' + that.data.j_id + '&overtime=' + overtime + '&ifgb=' + ifgb + '&ifpay=' + ifpay + '&c_id=' + c_id,
                              })
                            } else {
                              app.util.request({
                                'url': 'entry/wxapp/yuyue.paywenzhen',
                                header: {
                                  "Content-Type": "application/xml"
                                },
                                method: "GET",
                                data: {
                                  openid: wx.getStorageSync('openid'),
                                  z_tw_money: paymoney,
                                  orders: orders,
                                  key_words: key_words,
                                  coupon_id: pay_info.coupon_id
                                },
                                success: function (res) {
                                  console.log(res);
                                  wx.requestPayment({
                                    'timeStamp': res.data.timeStamp,
                                    'nonceStr': res.data.nonceStr, //字符串随机数
                                    'package': res.data.package,
                                    'signType': res.data.signType,
                                    'paySign': res.data.paySign,
                                    success: function (res) {
                                      console.log(res)
                                      //产生分销提成
                                      if (ziji == 0) {
                                        app.util.request({
                                          'url': 'entry/wxapp/tuike.uptopmoney',
                                          data: {
                                            tkid: tkid,
                                            mytkid: mytkid,
                                            money: pay_info.money,
                                            openid: wx.getStorageSync('openid'),
                                            orders: orders
                                          },
                                          success: function (res) {
                                            console.log(res)
                                          }
                                        })
                                      }
                                      that.getUpdate();
                                      app.util.request({
                                        'url': 'entry/wxapp/yuyue.upchufangwentype',
                                        data: {
                                          orders: orders,
                                        },
                                        success: function (res) {
                                          console.log(res)

                                        }
                                      })
                                      app.util.request({
                                        'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
                                        data: {
                                          id: id,
                                          val: conets.text,
                                          near: '开处方',
                                          zid: zid,
                                          type: "user"
                                        },
                                        success: function (res) {
                                          console.log(res)
                                        }
                                      })
                                      app.util.request({
                                        'url': 'entry/wxapp/yuyue.kfangmsgdh',
                                        data: {
                                          orders: orders
                                        },
                                        success: function (res) {
                                          console.log(res)
                                        }
                                      })
                                      wx.navigateTo({
                                        url: '../zhifuend/zhifuend?txt=yes&zid=' + that.data.zid + '&back_orser=' + back_orser + '&key_words=' + key_words + '&j_id=' + that.data.j_id + '&overtime=' + overtime + '&ifgb=' + ifgb + '&ifpay=' + ifpay + '&c_id=' + c_id,
                                      })
                                    },
                                    fail: function (res) {
                                      console.log(res)
                                    }
                                  })
                                }
                              })
                            }
                          }
                        })
                      }
                    }
                  })
                  return false;
                } else {
                  //图文问诊
                  if (key_words == 'tuwenwenzhen') {

                    wx.showModal({
                      title: title,
                      success: function (res) {
                        if (res.confirm) {
                          app.util.request({
                            'url': 'entry/wxapp/tuwen.addbl',
                            data: {
                              openid: wx.getStorageSync('openid'),
                              zid: zid,
                              key_words: key_words,
                              cfstate: cfstate,
                              conets: conets,
                              money: pay_info.money,
                              j_id: j_id,
                              ifgk: ifgk,
                              addnum: addnum,
                              biaoqian: biaoqian,
                              coupon_dk: pay_info.coupon_dk,
                              old_money: old_money,
                              coupon_id: pay_info.coupon_id,
                              yid: pay_info.yid,
                              year_dk: pay_info.year_dk
                            },
                            success: function (res) {
                              console.log(res)
                              var orders = res.data.orders
                              var back_orser = res.data.back_orser
                              var id = res.data.id
                              var overtime = res.data.overtime
                              var ifpay = res.data.ifpay
                              var ifgb = res.data.ifgb
                              var listArr = {
                                advertisement: that.data.advertisement,
                                dex: 0,
                                ifpay: ifpay,
                                j_id: that.data.j_id,
                                money: pay_info.money,
                                orders: orders,
                                overtime: overtime,
                                z_name: that.data.z_name,
                                zid: that.data.zid
                              }
                              var list = JSON.stringify(listArr)
                              if (ifgk == 1) {
                                app.util.request({
                                  'url': 'entry/wxapp/user.openquestion',
                                  data: {
                                    id: id,
                                    key_words: key_words,
                                    back_orser: back_orser
                                  },
                                  success: function (res) {
                                    console.log(res)
                                  }
                                })
                              }
                              if (pay_info.money != '0.00' && pay_info.money != '0') {
                                app.util.request({
                                  'url': 'entry/wxapp/yuyue.paywenzhen',
                                  header: {
                                    "Content-Type": "application/xml"
                                  },
                                  method: "GET",
                                  data: {
                                    openid: wx.getStorageSync('openid'),
                                    z_tw_money: pay_info.money,
                                    orders: orders,
                                    key_words: key_words
                                  },
                                  success: function (res) {
                                    console.log(res);
                                    wx.requestPayment({
                                      'timeStamp': res.data.timeStamp,
                                      'nonceStr': res.data.nonceStr, //字符串随机数
                                      'package': res.data.package,
                                      'signType': res.data.signType,
                                      'paySign': res.data.paySign,
                                      success: function (res) {
                                        console.log(res)

                                      },
                                      fail: function (res) {
                                        console.log(res)
                                      },
                                      'complete': function (res) {
                                        console.log('支付完成');
                                        console.log(res.errMsg);

                                        if (res.errMsg == 'requestPayment:ok') {
                                          that.getUpdate();
                                          //产生分销提成
                                          if (ziji == 0) {
                                            app.util.request({
                                              'url': 'entry/wxapp/tuike.uptopmoney',
                                              data: {
                                                tkid: tkid,
                                                mytkid: mytkid,
                                                money: pay_info.money,
                                                openid: wx.getStorageSync('openid'),
                                                leixing: 'tuwenwenzhen',
                                                orders: orders
                                              },
                                              success: function (res) {
                                                console.log(res)
                                              }
                                            })
                                          }
                                          //提醒医生
                                          app.util.request({
                                            'url': 'entry/wxapp/yuyue.tuwenmsgdh',
                                            data: {
                                              orders: orders,

                                            },
                                            success: function (res) {
                                              console.log(res)
                                            }
                                          })
                                          if (ifgk == 1) {
                                            app.util.request({
                                              'url': 'entry/wxapp/user.openquestion',
                                              data: {
                                                id: id,
                                                key_words: key_words,
                                                back_orser: back_orser
                                              },
                                              success: function (res) {
                                                console.log(res)
                                              }
                                            })
                                          }
                                          console.log(orders);
                                          app.util.request({
                                            'url': 'entry/wxapp/yuyue.uptuwentype',
                                            data: {
                                              orders: orders,
                                            },
                                            success: function (res) {
                                              console.log(res)

                                            }
                                          })
                                          app.util.request({
                                            'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
                                            data: {
                                              id: id,
                                              val: conets.text,
                                              near: '图文',
                                              zid: that.data.zid,
                                              type: "user"
                                            },
                                            success: function (res) {
                                              console.log(res)
                                            }
                                          })
                                          app.util.request({
                                            'url': 'entry/wxapp/yuyue.tuwenmsgdh',
                                            data: {
                                              orders: orders
                                            },
                                            success: function (res) {
                                              console.log(res)
                                              wx.navigateTo({
                                                url: "/hyb_yl/czhuanjiasubpages/pages/chatroom/chatroom?username={}" + '&list=' + list + '&z_name=' + that.data.z_name + '&orders=' + orders + '&key_words=' + key_words + '&ifpay=' + ifpay + '&money=' + pay_info.money + '&overtime=' + overtime + '&currentData=' + ifpay + '&ifgb=' + ifgb,
                                              })
                                            }
                                          })
                                          return;
                                        }
                                      }
                                    })
                                  }
                                })
                              } else {
                                that.getUpdate();
                                app.util.request({
                                  'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
                                  data: {
                                    id: id,
                                    val: conets.text,
                                    near: '图文',
                                    zid: that.data.zid,
                                    type: "user"
                                  },
                                  success: function (res) {
                                    console.log(res)
                                  }
                                })

                                app.util.request({
                                  'url': 'entry/wxapp/yuyue.tuwenmsgdh',
                                  data: {
                                    orders: orders
                                  },
                                  success: function (res) {
                                    console.log(res)
                                    wx.navigateTo({
                                      url: "/hyb_yl/czhuanjiasubpages/pages/chatroom/chatroom?username={}" + '&list=' + list + '&z_name=' + that.data.z_name + '&orders=' + orders + '&key_words=' + key_words + '&ifpay=' + ifpay + '&money=' + pay_info.money + '&overtime=' + overtime + '&currentData=' + ifpay + '&ifgb=' + ifgb,
                                    })
                                  }
                                })
                                return;

                              }
                            }
                          })
                        }
                      }
                    })
                  }
                  //电话预约
                  if (key_words == 'dianhuajizhen') {
                    var openid = wx.getStorageSync('openid')
                    var phone = that.data.phone
                    var time_leng = that.data.time_leng
                    app.util.request({
                      'url': 'entry/wxapp/yuyue.telladd1',
                      data: {
                        zid: zid,
                        tell: phone,
                        describe: conets,
                        openid: wx.getStorageSync('openid'),
                        keywords: key_words,
                        year: that.data.data_time,
                        month_time: that.data.month_time,
                        week: that.data.week,
                        money: pay_info.money,
                        min: time_leng,
                        j_id: that.data.j_id,
                        roomID: roomID,
                        sdkAppID: userSig.sdkAppID,
                        template: '1v1',
                        userId2: that.data.userID,
                        userSig2: userSig.userSig,
                        addnum: addnum,
                        privateNum: privateNum,
                        coupon_dk: pay_info.coupon_dk,
                        old_money: old_money,
                        coupon_id: pay_info.coupon_id,
                        yid: pay_info.yid,
                        year_dk: pay_info.year_dk
                      },
                      success: function (res) {
                        console.log(res)
                        var orders = res.data.orders
                        var back_orser = res.data.back_orser
                        var id = res.data.id
                        var overtime = res.data.overtime
                        var ifpay = res.data.ifpay
                        var ifgb = res.data.ifgb
                        if (ifgk == 1) {
                          app.util.request({
                            'url': 'entry/wxapp/user.openquestion',
                            data: {
                              id: id,
                              key_words: key_words,
                              back_orser: back_orser
                            },
                            success: function (res) {
                              console.log(res)
                            }
                          })
                        }
                        if (pay_info.money == '0.00' || pay_info.money == '0') {
                          that.getUpdate();
                          app.util.request({
                            'url': 'entry/wxapp/yuyue.telmsgdh',
                            data: {
                              orders: orders,
                              text: '电话问诊'
                            },
                            success: function (res) {
                              console.log(res)

                            }
                          })
                          //模板消息提醒
                          app.util.request({
                            'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
                            data: {
                              id: id,
                              val: conets.text,
                              near: '电话',
                              zid: that.data.zid,
                              type: "user"
                            },
                            success: function (res) {
                              console.log(res)
                            }
                          })
                          wx.showToast({
                            title: '预约成功，请保持电话畅通！',
                            icon: 'none',
                            success: function () {
                              setTimeout(function () {
                                wx.navigateTo({
                                  url: '../zhifuend/zhifuend?txt=yes&zid=' + that.data.zid + '&back_orser=' + back_orser + '&key_words=' + key_words + '&j_id=' + that.data.j_id + '&overtime=' + overtime + '&ifpay=' + ifpay + '&ifgb=' + ifgb,
                                })
                              }, 1900)
                            }
                          })
                          return;

                        } else {
                          app.util.request({
                            'url': 'entry/wxapp/yuyue.paywenzhen',
                            header: {
                              "Content-Type": "application/xml"
                            },
                            method: "GET",
                            data: {
                              openid: wx.getStorageSync('openid'),
                              z_tw_money: pay_info.money,
                              orders: orders,
                              key_words: key_words
                            },
                            success: function (res) {
                              console.log(res);
                              wx.requestPayment({
                                'timeStamp': res.data.timeStamp,
                                'nonceStr': res.data.nonceStr, //字符串随机数
                                'package': res.data.package,
                                'signType': res.data.signType,
                                'paySign': res.data.paySign,
                                success: function (res) {
                                  console.log(res)

                                },
                                fail: function (res) {
                                  console.log(res)

                                },
                                'complete': function (res) {
                                  //更新问诊时间

                                  if (res.errMsg == 'requestPayment:ok') {
                                    that.getUpdate();
                                    //产生分销提成
                                    if (ziji == 0) {
                                      app.util.request({
                                        'url': 'entry/wxapp/tuike.uptopmoney',
                                        data: {
                                          tkid: tkid,
                                          mytkid: mytkid,
                                          money: pay_info.money,
                                          openid: wx.getStorageSync('openid'),
                                          leixing: 'dianhuajizhen',
                                          orders: orders
                                        },
                                        success: function (res) {
                                          console.log(res)
                                        }
                                      })
                                    }
                                    if (ifgk == 1) {
                                      app.util.request({
                                        'url': 'entry/wxapp/user.openquestion',
                                        data: {
                                          id: id,
                                          key_words: key_words,
                                          back_orser: back_orser
                                        },
                                        success: function (res) {
                                          console.log(res)
                                        }
                                      })
                                    }
                                    app.util.request({
                                      'url': 'entry/wxapp/yuyue.upwenzhentype',
                                      data: {
                                        orders: orders,
                                      },
                                      success: function (res) {
                                        console.log(res)

                                      }
                                    })
                                    app.util.request({
                                      'url': 'entry/wxapp/yuyue.telmsgdh',
                                      data: {
                                        orders: orders,
                                      },
                                      success: function (res) {
                                        console.log(res)

                                      }
                                    })
                                    //模板消息提醒
                                    app.util.request({
                                      'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
                                      data: {
                                        id: id,
                                        val: conets.text,
                                        near: '电话',
                                        zid: that.data.zid,
                                        type: "user"
                                      },
                                      success: function (res) {
                                        console.log(res)
                                      }
                                    })
                                    wx.showToast({
                                      title: '预约成功，请保持电话畅通！',
                                      icon: 'none',
                                      success: function () {
                                        setTimeout(function () {
                                          wx.navigateTo({
                                            url: '../zhifuend/zhifuend?txt=yes&zid=' + that.data.zid + '&back_orser=' + back_orser + '&key_words=' + key_words + '&j_id=' + that.data.j_id + '&overtime=' + overtime + '&ifpay=' + ifpay + '&ifgb=' + ifgb,
                                          })
                                        }, 1900)
                                      }
                                    })
                                    return;
                                  }
                                }
                              })
                            }
                          })
                        }
                      }
                    })
                    return false;
                  }
                  //视频预约
                  if (key_words == 'shipinwenzhen') {
                    var openid = wx.getStorageSync('openid')
                    var phone = that.data.phone
                    var time_leng = that.data.time_leng
                    app.util.request({
                      'url': 'entry/wxapp/yuyue.telladd1',
                      data: {
                        zid: zid,
                        tell: phone,
                        describe: conets,
                        openid: wx.getStorageSync('openid'),
                        keywords: key_words,
                        year: that.data.data_time,
                        month_time: that.data.month_time,
                        week: that.data.week,
                        money: pay_info.money,
                        min: time_leng,
                        j_id: that.data.j_id,
                        roomID: roomID,
                        sdkAppID: userSig.sdkAppID,
                        template: '1v1',
                        userId2: that.data.userID,
                        userSig2: userSig.userSig,
                        addnum: addnum,
                        privateNum: privateNum,
                        coupon_dk: pay_info.coupon_dk,
                        old_money: old_money,
                        coupon_id: pay_info.coupon_id,
                        yid: pay_info.yid,
                        year_dk: pay_info.year_dk
                      },
                      success: function (res) {
                        console.log(res)
                        var orders = res.data.orders
                        var back_orser = res.data.back_orser
                        var id = res.data.id
                        var overtime = res.data.overtime
                        var ifpay = res.data.ifpay
                        var ifgb = res.data.ifgb
                        if (ifgk == 1) {
                          app.util.request({
                            'url': 'entry/wxapp/user.openquestion',
                            data: {
                              id: id,
                              key_words: key_words,
                              back_orser: back_orser
                            },
                            success: function (res) {
                              console.log(res)
                            }
                          })
                        }
                        if (pay_info.money == '0.00' || pay_info.money == '0') {
                          that.getUpdate();
                          app.util.request({
                            'url': 'entry/wxapp/yuyue.vidomsgdh',
                            data: {
                              orders: orders,
                            },
                            success: function (res) {
                              console.log(res)
                              app.util.request({
                                'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
                                data: {
                                  id: id,
                                  val: conets.text,
                                  near: '视频',
                                  zid: that.data.zid,
                                  type: "user"
                                },
                                success: function (res) {
                                  console.log(res)
                                }
                              })
                            }
                          })
                          wx.showToast({
                            title: '预约成功！',
                            icon: 'none',
                            success: function () {
                              setTimeout(function () {
                                wx.navigateTo({
                                  url: '../zhifuend/zhifuend?txt=yes&zid=' + that.data.zid + '&back_orser=' + back_orser + '&key_words=' + key_words + '&j_id=' + that.data.j_id + '&overtime=' + overtime + '&ifpay=' + ifpay + '&ifgb=' + ifgb,
                                })
                              }, 1900)
                            }
                          })
                          return;

                        } else {
                          app.util.request({
                            'url': 'entry/wxapp/yuyue.paywenzhen',
                            header: {
                              "Content-Type": "application/xml"
                            },
                            method: "GET",
                            data: {
                              openid: wx.getStorageSync('openid'),
                              z_tw_money: pay_info.money,
                              orders: orders,
                              key_words: key_words
                            },
                            success: function (res) {
                              console.log(res);

                              wx.requestPayment({
                                'timeStamp': res.data.timeStamp,
                                'nonceStr': res.data.nonceStr, //字符串随机数
                                'package': res.data.package,
                                'signType': res.data.signType,
                                'paySign': res.data.paySign,
                                success: function (res) {
                                  console.log(res)

                                },
                                fail: function (res) {
                                  console.log(res)

                                },
                                'complete': function (res) {
                                  if (res.errMsg == 'requestPayment:ok') {
                                    that.getUpdate();
                                    //产生分销提成
                                    if (ziji == 0) {
                                      app.util.request({
                                        'url': 'entry/wxapp/tuike.uptopmoney',
                                        data: {
                                          tkid: tkid,
                                          mytkid: mytkid,
                                          money: pay_info.money,
                                          openid: wx.getStorageSync('openid'),
                                          leixing: 'shipinwenzhen',
                                          orders: orders
                                        },
                                        success: function (res) {
                                          console.log(res)
                                        }
                                      })
                                    }
                                    if (ifgk == 1) {
                                      app.util.request({
                                        'url': 'entry/wxapp/user.openquestion',
                                        data: {
                                          id: id,
                                          key_words: key_words,
                                          back_orser: back_orser
                                        },
                                        success: function (res) {
                                          console.log(res)
                                        }
                                      })
                                    }
                                    app.util.request({
                                      'url': 'entry/wxapp/yuyue.upwenzhentype',
                                      data: {
                                        orders: orders,
                                      },
                                      success: function (res) {
                                        console.log(res)

                                      }
                                    })
                                    app.util.request({
                                      'url': 'entry/wxapp/yuyue.vidomsgdh',
                                      data: {
                                        orders: orders,
                                      },
                                      success: function (res) {
                                        console.log(res)
                                      }
                                    })
                                    //模板消息提醒
                                    app.util.request({
                                      'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
                                      data: {
                                        id: id,
                                        val: conets.text,
                                        near: '视频',
                                        zid: that.data.zid,
                                        type: "user"
                                      },
                                      success: function (res) {
                                        console.log(res)
                                      }
                                    })
                                    wx.showToast({
                                      title: '预约成功！',
                                      icon: 'none',
                                      success: function () {
                                        setTimeout(function () {
                                          wx.navigateTo({
                                            url: '../zhifuend/zhifuend?txt=yes&zid=' + that.data.zid + '&back_orser=' + back_orser + '&key_words=' + key_words + '&j_id=' + that.data.j_id + '&overtime=' + overtime + '&ifpay=' + ifpay + '&ifgb=' + ifgb,
                                          })
                                        }, 1900)
                                      }
                                    })
                                    return;
                                  }
                                }
                              })
                            }
                          })
                        }
                      }
                    })
                    return false;
                  }
                  //开处方c_id
                  if (key_words == 'yuanchengkaifang') {
                    wx.showModal({
                      title: '是否支付',
                      success: function (res) {
                        if (res.confirm) {

                          app.util.request({
                            'url': 'entry/wxapp/user.addcforder',
                            data: {
                              openid: wx.getStorageSync('openid'),
                              zid: zid,
                              key_words: key_words,
                              cfstate: cfstate,
                              conets: conets,
                              money: pay_info.money,
                              j_id: j_id,
                              ifgk: ifgk,
                              addnum: addnum,
                              coupon_dk: pay_info.coupon_dk,
                              old_money: old_money,
                              coupon_id: pay_info.coupon_id,
                              yid: pay_info.yid,
                              year_dk: pay_info.year_dk
                            },
                            success: function (res) {
                              console.log(res)
                              var orders = res.data.orders
                              var back_orser = res.data.back_orser
                              var id = res.data.c_id
                              var c_id = res.data.c_id
                              var overtime = res.data.overtime
                              var ifpay = res.data.ispay
                              var ifgb = res.data.ifgb
                              if (ifgk == 1) {
                                app.util.request({
                                  'url': 'entry/wxapp/user.openquestion',
                                  data: {
                                    id: id,
                                    key_words: key_words,
                                    back_orser: back_orser
                                  },
                                  success: function (res) {
                                    console.log(res)
                                  }
                                })
                              }
                              if (pay_info.money == '0.00' || pay_info.money == '0') {
                                that.getUpdate();
                                app.util.request({
                                  'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
                                  data: {
                                    id: id,
                                    val: conets.text,
                                    near: '开处方',
                                    zid: zid,
                                    type: "user"
                                  },
                                  success: function (res) {
                                    console.log(res)
                                  }
                                })
                                app.util.request({
                                  'url': 'entry/wxapp/yuyue.kfangmsgdh',
                                  data: {
                                    orders: orders,
                                  },
                                  success: function (res) {
                                    console.log(res)

                                  }
                                })
                                wx.navigateTo({
                                  url: '../zhifuend/zhifuend?txt=yes&zid=' + that.data.zid + '&back_orser=' + back_orser + '&key_words=' + key_words + '&j_id=' + that.data.j_id + '&overtime=' + overtime + '&ifpay=' + ifpay + '&ifgb=' + ifgb + '&c_id=' + c_id,
                                })
                              } else {
                                app.util.request({
                                  'url': 'entry/wxapp/yuyue.paywenzhen',
                                  header: {
                                    "Content-Type": "application/xml"
                                  },
                                  method: "GET",
                                  data: {
                                    openid: wx.getStorageSync('openid'),
                                    z_tw_money: pay_info.money,
                                    orders: orders,
                                    key_words: key_words,
                                    coupon_id: pay_info.coupon_id
                                  },
                                  success: function (res) {
                                    console.log(res);
                                    wx.requestPayment({
                                      'timeStamp': res.data.timeStamp,
                                      'nonceStr': res.data.nonceStr, //字符串随机数
                                      'package': res.data.package,
                                      'signType': res.data.signType,
                                      'paySign': res.data.paySign,
                                      success: function (res) {
                                        console.log(res)
                                        that.getUpdate();
                                        //产生分销提成
                                        if (ziji == 0) {
                                          app.util.request({
                                            'url': 'entry/wxapp/tuike.uptopmoney',
                                            data: {
                                              tkid: tkid,
                                              mytkid: mytkid,
                                              money: pay_info.money,
                                              openid: wx.getStorageSync('openid'),
                                              leixing: 'yuanchengkaifang',
                                              orders: orders
                                            },
                                            success: function (res) {
                                              console.log(res)
                                            }
                                          })
                                        }
                                        app.util.request({
                                          'url': 'entry/wxapp/yuyue.upchufangwentype',
                                          data: {
                                            orders: orders,
                                          },
                                          success: function (res) {
                                            console.log(res)

                                          }
                                        })

                                        app.util.request({
                                          'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
                                          data: {
                                            id: id,
                                            val: conets.text,
                                            near: '开处方',
                                            zid: zid,
                                            type: "user"
                                          },
                                          success: function (res) {
                                            console.log(res)
                                          }
                                        })
                                        wx.navigateTo({
                                          url: '../zhifuend/zhifuend?txt=yes&zid=' + that.data.zid + '&back_orser=' + back_orser + '&key_words=' + key_words + '&j_id=' + that.data.j_id + '&overtime=' + overtime + '&ifpay=' + ifpay + '&ifgb=' + ifgb + '&c_id=' + c_id,
                                        })
                                      },
                                      fail: function (res) {
                                        console.log(res)
                                      }
                                    })
                                  }
                                })
                              }
                            }
                          })
                        }
                      }
                    })
                    return false;
                  }
                  // 手术快约
                  if (key_words == 'shoushukuaiyue') {
                    var openid = wx.getStorageSync('openid')
                    var phone = that.data.phone
                    var time_leng = that.data.time_leng
                    var tjorder = that.data.tjorder
                    app.util.request({
                      'url': 'entry/wxapp/yuyue.telladd1',
                      data: {
                        zid: zid,
                        tell: phone,
                        describe: conets,
                        openid: wx.getStorageSync('openid'),
                        keywords: key_words,
                        year: that.data.data_time,
                        month_time: that.data.month_time,
                        week: that.data.week,
                        money: pay_info.money,
                        min: time_leng,
                        j_id: that.data.j_id,
                        roomID: roomID,
                        sdkAppID: userSig.sdkAppID,
                        template: '1v1',
                        userId2: that.data.userID,
                        userSig2: userSig.userSig,
                        addnum: addnum,
                        privateNum: privateNum,
                        coupon_dk: pay_info.coupon_dk,
                        old_money: old_money,
                        coupon_id: pay_info.coupon_id,
                        yid: pay_info.yid,
                        year_dk: pay_info.year_dk,

                      },
                      success: function (res) {
                        console.log(res)
                        var orders = res.data.orders
                        var back_orser = res.data.back_orser
                        var id = res.data.id
                        var overtime = res.data.overtime
                        var ifpay = res.data.ifpay
                        var ifgb = res.data.ifgb
                        if (pay_info.money == '0.00' || pay_info.money == '0') {
                          that.getUpdate();
                          app.util.request({
                            'url': 'entry/wxapp/yuyue.msgdh',
                            data: {
                              orders: orders,
                              text: '手术快约'
                            },
                            success: function (res) {
                              console.log(res)

                            }
                          })
                          //模板消息提醒
                          app.util.request({
                            'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
                            data: {
                              id: id,
                              val: conets.text,
                              near: '手术快约',
                              zid: that.data.zid
                            },
                            success: function (res) {
                              console.log(res)
                            }
                          })
                          if (ifgk == 1) {
                            app.util.request({
                              'url': 'entry/wxapp/user.openquestion',
                              data: {
                                id: id,
                                key_words: key_words,
                                back_orser: back_orser
                              },
                              success: function (res) {
                                console.log(res)
                              }
                            })
                          }
                          wx.showToast({
                            title: '预约成功！',
                            icon: 'none',
                            success: function () {
                              setTimeout(function () {
                                wx.navigateTo({
                                  url: '../zhifuend/zhifuend?txt=yes&zid=' + that.data.zid + '&back_orser=' + back_orser + '&key_words=' + key_words + '&j_id=' + that.data.j_id + '&overtime=' + overtime + '&ifpay=' + ifpay + '&ifgb=' + ifgb,
                                })
                              }, 1900)
                            }
                          })
                          return;
                        } else {
                          app.util.request({
                            'url': 'entry/wxapp/yuyue.paywenzhen',
                            header: {
                              "Content-Type": "application/xml"
                            },
                            method: "GET",
                            data: {
                              openid: wx.getStorageSync('openid'),
                              z_tw_money: pay_info.money,
                              orders: orders,
                              key_words: key_words
                            },
                            success: function (res) {
                              console.log(res);
                              wx.requestPayment({
                                'timeStamp': res.data.timeStamp,
                                'nonceStr': res.data.nonceStr, //字符串随机数
                                'package': res.data.package,
                                'signType': res.data.signType,
                                'paySign': res.data.paySign,
                                success: function (res) {
                                  console.log(res)

                                },
                                fail: function (res) {
                                  console.log(res)

                                },
                                'complete': function (res) {
                                  
                                  //产生分销提成
                                  if (ziji == 0) {
                                    app.util.request({
                                      'url': 'entry/wxapp/tuike.uptopmoney',
                                      data: {
                                        tkid: tkid,
                                        mytkid: mytkid,
                                        money: pay_info.money,
                                        openid: wx.getStorageSync('openid'),
                                        leixing: 'shoushukuaiyue',
                                        orders: orders
                                      },
                                      success: function (res) {
                                        console.log(res)
                                      }
                                    })
                                  }
                                  if (res.errMsg == 'requestPayment:ok') {
                                    that.getUpdate();
                                    if (ifgk == 1) {
                                      app.util.request({
                                        'url': 'entry/wxapp/user.openquestion',
                                        data: {
                                          id: id,
                                          key_words: key_words,
                                          back_orser: back_orser
                                        },
                                        success: function (res) {
                                          console.log(res)
                                        }
                                      })
                                    }
                                    app.util.request({
                                      'url': 'entry/wxapp/yuyue.upwenzhentype',
                                      data: {
                                        orders: orders,
                                      },
                                      success: function (res) {
                                        console.log(res)

                                      }
                                    })
                                    app.util.request({
                                      'url': 'entry/wxapp/yuyue.shouangmsgdh',
                                      data: {
                                        orders: orders,
                                        text: '手术快约'
                                      },
                                      success: function (res) {
                                        console.log(res)

                                      }
                                    })
                                    //模板消息提醒
                                    app.util.request({
                                      'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
                                      data: {
                                        id: id,
                                        val: conets.text,
                                        near: '手术快约',
                                        zid: that.data.zid
                                      },
                                      success: function (res) {
                                        console.log(res)
                                      }
                                    })
                                    wx.showToast({
                                      title: '预约成功！',
                                      icon: 'none',
                                      success: function () {
                                        setTimeout(function () {
                                          wx.navigateTo({
                                            url: '../zhifuend/zhifuend?txt=yes&zid=' + that.data.zid + '&back_orser=' + back_orser + '&key_words=' + key_words + '&j_id=' + that.data.j_id + '&overtime=' + overtime + '&ifpay=' + ifpay + '&ifgb=' + ifgb,
                                          })
                                        }, 1900)
                                      }
                                    })
                                    return;
                                  }
                                }
                              })
                            }
                          })
                        }
                      }
                    })

                    return false;
                  }
                  // 报告解读
                  if (key_words == 'tijianjiedu') {
                    var openid = wx.getStorageSync('openid')
                    var phone = that.data.phone
                    var time_leng = that.data.time_leng
                    app.util.request({
                      'url': 'entry/wxapp/yuyue.telladd1',
                      data: {
                        zid: zid,
                        tell: phone,
                        describe: conets,
                        openid: wx.getStorageSync('openid'),
                        keywords: key_words,
                        year: that.data.data_time,
                        month_time: that.data.month_time,
                        week: that.data.week,
                        money: pay_info.money,
                        min: time_leng,
                        j_id: that.data.j_id,
                        roomID: roomID,
                        sdkAppID: userSig.sdkAppID,
                        template: '1v1',
                        userId2: that.data.userID,
                        userSig2: userSig.userSig,
                        addnum: addnum,
                        privateNum: privateNum,
                        coupon_dk: pay_info.coupon_dk,
                        old_money: old_money,
                        coupon_id: pay_info.coupon_id,
                        yid: pay_info.yid,
                        year_dk: pay_info.year_dk,
                        tjorder: that.data.tjorder
                      },
                      success: function (res) {
                        console.log(res)
                        var orders = res.data.orders
                        var back_orser = res.data.back_orser
                        var id = res.data.id
                        var overtime = res.data.overtime
                        var ifpay = res.data.ifpay
                        var ifgb = res.data.ifgb

                        if (pay_info.money == '0.00' || pay_info.money == '0') {
                          that.getUpdate();
                          wx.showToast({
                            title: '预约成功！',
                            icon: 'none',
                            success: function () {
                              app.util.request({
                                'url': 'entry/wxapp/yuyue.tijianmsgdh',
                                data: {
                                  orders: orders,
                                },
                                success: function (res) {
                                  console.log(res)

                                }
                              })
                              if (ifgk == 1) {
                                app.util.request({
                                  'url': 'entry/wxapp/user.openquestion',
                                  data: {
                                    id: id,
                                    key_words: key_words,
                                    back_orser: back_orser
                                  },
                                  success: function (res) {
                                    console.log(res)
                                  }
                                })
                              }
                              //模板消息提醒
                              app.util.request({
                                'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
                                data: {
                                  id: id,
                                  val: conets.text,
                                  near: '报告解读',
                                  zid: that.data.zid
                                },
                                success: function (res) {
                                  console.log(res)
                                }
                              })
                              setTimeout(function () {
                                wx.navigateTo({
                                  url: '../zhifuend/zhifuend?txt=yes&zid=' + that.data.zid + '&back_orser=' + back_orser + '&key_words=' + key_words + '&j_id=' + that.data.j_id + '&overtime=' + overtime + '&ifpay=' + ifpay + '&ifgb=' + ifgb + '&id=' + id,
                                })
                              }, 1900)
                            }
                          })
                          return;

                        } else {
                          app.util.request({
                            'url': 'entry/wxapp/yuyue.paywenzhen',
                            header: {
                              "Content-Type": "application/xml"
                            },
                            method: "GET",
                            data: {
                              openid: wx.getStorageSync('openid'),
                              z_tw_money: pay_info.money,
                              orders: orders,
                              key_words: key_words
                            },
                            success: function (res) {
                              console.log(res);
                              wx.requestPayment({
                                'timeStamp': res.data.timeStamp,
                                'nonceStr': res.data.nonceStr, //字符串随机数
                                'package': res.data.package,
                                'signType': res.data.signType,
                                'paySign': res.data.paySign,
                                success: function (res) {
                                  console.log(res)

                                },
                                fail: function (res) {
                                  console.log(res)

                                },
                                'complete': function (res) {
                                  //产生分销提成
                                  if (ziji == 0) {
                                    app.util.request({
                                      'url': 'entry/wxapp/tuike.uptopmoney',
                                      data: {
                                        tkid: tkid,
                                        mytkid: mytkid,
                                        money: pay_info.money,
                                        openid: wx.getStorageSync('openid'),
                                        leixing: 'tijianjiedu',
                                        orders: orders
                                      },
                                      success: function (res) {
                                        console.log(res)
                                      }
                                    })
                                  }
                                  if (res.errMsg == 'requestPayment:ok') {
                                    that.getUpdate();
                                    if (ifgk == 1) {
                                      app.util.request({
                                        'url': 'entry/wxapp/user.openquestion',
                                        data: {
                                          id: id,
                                          key_words: key_words,
                                          back_orser: back_orser
                                        },
                                        success: function (res) {
                                          console.log(res)
                                        }
                                      })
                                    }
                                    app.util.request({
                                      'url': 'entry/wxapp/yuyue.upwenzhentype',
                                      data: {
                                        orders: orders,
                                      },
                                      success: function (res) {
                                        console.log(res)

                                      }
                                    })
                                    app.util.request({
                                      'url': 'entry/wxapp/yuyue.tijianmsgdh',
                                      data: {
                                        orders: orders,
                                      },
                                      success: function (res) {
                                        console.log(res)

                                      }
                                    })
                                    //模板消息提醒
                                    app.util.request({
                                      'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
                                      data: {
                                        id: id,
                                        val: conets.text,
                                        near: '报告解读',
                                        zid: that.data.zid
                                      },
                                      success: function (res) {
                                        console.log(res)
                                      }
                                    })

                                    wx.showToast({
                                      title: '预约成功！',
                                      icon: 'none',
                                      success: function () {
                                        setTimeout(function () {
                                          wx.navigateTo({
                                            url: '../zhifuend/zhifuend?txt=yes&zid=' + that.data.zid + '&back_orser=' + back_orser + '&key_words=' + key_words + '&j_id=' + that.data.j_id + '&overtime=' + overtime + '&ifpay=' + ifpay + '&ifgb=' + ifgb + '&id=' + id,
                                          })
                                        }, 1900)
                                      }
                                    })
                                    return;
                                  }
                                }
                              })
                            }
                          })
                        }
                      }
                    })
                    return false;
                  }
                  // 挂号预约
                  if (key_words == 'yuanchengguahao') {
                    var openid = wx.getStorageSync('openid')
                    var phone = that.data.phone
                    var time_leng = that.data.time_leng
                    app.util.request({
                      'url': 'entry/wxapp/zhuanjia.add_ghorder',
                      data: {
                        zid: zid,
                        tell: phone,
                        describe: conets,
                        openid: wx.getStorageSync('openid'),
                        keywords: key_words,
                        year: that.data.data_time,
                        month_time: that.data.month_time,
                        week: that.data.week,
                        money: pay_info.money,
                        min: time_leng,
                        j_id: that.data.j_id,
                        roomID: roomID,
                        sdkAppID: userSig.sdkAppID,
                        template: '1v1',
                        userId2: that.data.userID,
                        userSig2: userSig.userSig,
                        addnum: addnum,
                        privateNum: privateNum,
                        coupon_dk: pay_info.coupon_dk,
                        old_money: old_money,
                        coupon_id: pay_info.coupon_id,
                        yid: pay_info.yid,
                        year_dk: pay_info.year_dk
                      },
                      success: function (res) {
                        console.log(res)
                        var orders = res.data.orders
                        var back_orser = res.data.back_orser
                        var id = res.data.id
                        var ifpay = res.data.ifpay
                        var ifgb = res.data.ifgb

                        if (pay_info.money == '0.00' || pay_info.money == '0') {
                          that.getUpdate();
                          //模板消息通知
                          app.util.request({
                            'url': 'entry/wxapp/yuyue.mobelghmsgdh',
                            data: {
                              orders: orders,
                              keywords: '挂号'
                            },
                            success: function (res) {
                              console.log(res)
                            }
                          })


                          //短信提醒
                          app.util.request({
                            'url': 'entry/wxapp/yuyue.guhaomsgdh',
                            data: {
                              orders: orders,
                              text: '挂号预约'
                            },
                            success: function (res) {
                              console.log(res)

                            }
                          })
                          wx.showToast({
                            title: '预约成功！',
                            icon: 'none',
                            success: function () {
                              if (ifgk == 1) {
                                app.util.request({
                                  'url': 'entry/wxapp/user.openquestion',
                                  data: {
                                    id: id,
                                    key_words: key_words,
                                    back_orser: back_orser
                                  },
                                  success: function (res) {
                                    console.log(res)
                                  }
                                })
                              }
                              setTimeout(function () {

                                wx.navigateTo({
                                  url: '../zhifuend/zhifuend?txt=yes&zid=' + that.data.zid + '&back_orser=' + back_orser + '&key_words=' + key_words + '&j_id=' + that.data.j_id + '&ifgb=' + ifgb + '&ifpay=' + ifpay
                                })
                              }, 1900)
                            }
                          })
                          return;

                        } else {
                          app.util.request({
                            'url': 'entry/wxapp/yuyue.paywenzhen',
                            header: {
                              "Content-Type": "application/xml"
                            },
                            method: "GET",
                            data: {
                              openid: wx.getStorageSync('openid'),
                              z_tw_money: pay_info.money,
                              orders: orders,
                              key_words: key_words
                            },
                            success: function (res) {
                              console.log(res);
                              wx.requestPayment({
                                'timeStamp': res.data.timeStamp,
                                'nonceStr': res.data.nonceStr, //字符串随机数
                                'package': res.data.package,
                                'signType': res.data.signType,
                                'paySign': res.data.paySign,
                                success: function (res) {
                                  console.log(res)

                                },
                                fail: function (res) {
                                  console.log(res)

                                },
                                'complete': function (res) {
                                  //产生分销提成
                                  if (ziji == 0) {
                                    app.util.request({
                                      'url': 'entry/wxapp/tuike.uptopmoney',
                                      data: {
                                        tkid: tkid,
                                        mytkid: mytkid,
                                        money: pay_info.money,
                                        openid: wx.getStorageSync('openid'),
                                        leixing: 'yuanchengguahao',
                                        orders: orders
                                      },
                                      success: function (res) {
                                        console.log(res)
                                      }
                                    })
                                  }
                                  if (res.errMsg == 'requestPayment:ok') {
                                    that.getUpdate();
                                    if (ifgk == 1) {
                                      app.util.request({
                                        'url': 'entry/wxapp/user.openquestion',
                                        data: {
                                          id: id,
                                          key_words: key_words,
                                          back_orser: back_orser
                                        },
                                        success: function (res) {
                                          console.log(res)
                                        }
                                      })
                                    }
                                    app.util.request({
                                      'url': 'entry/wxapp/yuyue.updateghorder',
                                      data: {
                                        orders: orders,
                                      },
                                      success: function (res) {
                                        console.log(res)

                                      }
                                    })
                                    //模板消息通知
                                    app.util.request({
                                      'url': 'entry/wxapp/yuyue.mobelghmsgdh',
                                      data: {
                                        orders: orders,
                                      },
                                      success: function (res) {
                                        console.log(res)

                                      }
                                    })
                                    app.util.request({
                                      'url': 'entry/wxapp/yuyue.guhaomsgdh',
                                      data: {
                                        orders: orders,
                                        text: '挂号预约'
                                      },
                                      success: function (res) {
                                        console.log(res)

                                      }
                                    })
                                    wx.showToast({
                                      title: '预约成功！',
                                      icon: 'none',
                                      success: function () {
                                        setTimeout(function () {
                                          wx.navigateTo({
                                            url: '../zhifuend/zhifuend?txt=yes&zid=' + that.data.zid + '&back_orser=' + back_orser + '&key_words=' + key_words + '&j_id=' + that.data.j_id + '&ifgb=' + ifgb + '&ifpay=' + ifpay
                                          })

                                        }, 1900)
                                      }
                                    })
                                    return;
                                  }
                                }
                              })
                            }
                          })
                        }
                      }
                    })
                    return false;
                  }
                }

              }
            })
          } else {
            app.util.request({
              'url': "entry/wxapp/green.order",
              data: {
                openid: wx.getStorageSync('openid'),
                did: that.data.did,
                server: that.data.server,
                money: that.data.money,
                hid: that.data.hid,
                keshi_two: that.data.keshi_two,
                typeid: that.data.tid,
                content: that.data.conets,
                time: that.data.time,
                cfstate: that.data.cfstate,
                j_id: that.data.j_id,
                biaoqian: that.data.arr,
                zid: that.data.zid,
                fuwus: that.data.fuwus,
                week: that.data.week,
                time: that.data.time,
                start_time: that.data.timeText_start,
                end_time: that.data.timeText_end,
              },
              success: function (res) {
                var info = res.data;
                if (that.data.money == '' || that.data.money == '0' || that.data.money == '0.00') {
                  wx.showToast({
                    title: '预约成功！',
                    icon: 'none',
                    success: function () {
                      setTimeout(function () {
                        wx.reLaunch({
                          url: '/hyb_yl/lvtongserver/pages/orderdetail/orderdetail?txt=yes&did=' + that.data.did + '&back_orser=' + info.back_orser + '&key_words=' + info.key_words + '&j_id=' + that.data.j_id + '&zid=' + that.data.zid + '&j_id=' + that.data.j_id + '&ifpay=1' + '&money=' + that.data.money + '&id=' + info.id,
                        })
                      }, 1900)
                    }
                  })
                } else {
                  app.util.request({
                    'url': 'entry/wxapp/green.payorder',
                    header: {
                      "Content-Type": "application/xml"
                    },
                    method: "GET",
                    data: {
                      openid: wx.getStorageSync('openid'),
                      z_tw_money: info.money,
                      orders: info.orders,
                      key_words: that.data.server
                    },
                    success: function (res) {
                      console.log(res);
                      wx.requestPayment({
                        'timeStamp': res.data.timeStamp,
                        'nonceStr': res.data.nonceStr, //字符串随机数
                        'package': res.data.package,
                        'signType': res.data.signType,
                        'paySign': res.data.paySign,
                        success: function (res) {
                          console.log(res)

                        },
                        fail: function (res) {
                          console.log(res)

                        },
                        'complete': function (res) {
                          if (res.errMsg == 'requestPayment:ok') {
                            //产生分销提成
                            if (ziji == 0) {
                              app.util.request({
                                'url': 'entry/wxapp/tuike.uptopmoney',
                                data: {
                                  tkid: tkid,
                                  mytkid: mytkid,
                                  money: pay_info.money,
                                  openid: wx.getStorageSync('openid'),
                                  leixing: 'yuanchengguahao'
                                },
                                success: function (res) {
                                  console.log(res)
                                }
                              })
                            }
                            wx.showToast({
                              title: '预约成功！',
                              icon: 'none',
                              success: function () {
                                setTimeout(function () {
                                  wx.reLaunch({
                                    url: '/hyb_yl/lvtongserver/pages/orderdetail/orderdetail?txt=yes&did=' + that.data.did + '&back_orser=' + info.back_orser + '&key_words=' + info.key_words + '&j_id=' + that.data.j_id + '&zid=' + that.data.zid + '&j_id=' + that.data.j_id + '&ifpay=1' + '&money=' + that.data.money + '&id=' + info.id,
                                  })
                                }, 1900)
                              }
                            })
                            return;
                          }
                        }
                      })
                    }
                  })
                }
              }
            })
          }
        }
      }
    })

    //问诊申请开方
  },

  orderedbtn() {
    wx.navigateTo({
      url: '../orderedtime/orderedtime',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  onRadioChange(e) {
    console.log(e)
    this.setData({
      radio: !this.data.radio
    })
  }

})